"use strict";
/* Controllers */
app.controller("costQuotaAddController", ['$scope', '$location', '$rootScope', '$q','$routeParams', 'costQuotaAddService', function ($scope, $location, $rootScope, $q, $routeParams, costQuotaAddService) {

    var vm = $scope.vm = {};
    vm.p = {};
    vm.result = {};
    vm.p.id = $routeParams.id;

    var errorFn = function (result) {
        alert(result);
    };

    $scope.loadCostQuota = function() {
        var vm = $scope.vm;
        var params = vm.p;
        var procFn = function (res) {
            if (res.success && res.data) {
                vm.p = res.data
            } else {
                alert(res.msg);
            }
        };
        return costQuotaAddService.loadCostQuota(params, procFn, errorFn);
    }


    $scope.addCostQuota = function () {
        var vm = $scope.vm;
        var params = vm.p;
        var procFn = function (response) {
            if (response.success && response.data) {
                alert("添加成功！")
            } else {
                alert(response.msg);
            }
        };
        costQuotaAddService.addCostQuota(params, procFn, errorFn);
    };


    $scope.initializeController = function () {
        vm.result.ms = '';

        $scope.loadCostQuota();
    };

    $scope.initializeController();

}]);


/* Services */
app.service('costQuotaAddService', ['ajaxService', function (ajaxService) {


    this.loadCostQuota = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/cost_report/loadCostQuota.do", successFunction, errorFunction);
    };

    this.addCostQuota = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/cost_report/setCostQuota.do", successFunction, errorFunction);
    };

}]);

